using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Terra.Data.Entities.Identity;
using Terra.Data.Repository;

namespace Terra.Data.Repository.Identity
{
    /// <summary>
    /// 部门仓储接口
    /// </summary>
    public interface IDeptRepository : IRepository<Dept, Guid>
    {
        #region 基础查询

        /// <summary>
        /// 获取部门树状结构所需数据
        /// </summary>
        /// <param name="status">状态过滤，为空则获取所有状态</param>
        /// <returns>按排序号排序的部门列表</returns>
        Task<List<Dept>> GetDeptTreeDataAsync(int? status = null);

        /// <summary>
        /// 获取部门下拉选择列表所需数据
        /// </summary>
        /// <param name="status">状态过滤，为空则获取所有状态</param>
        /// <returns>按排序号排序的部门列表</returns>
        Task<List<Dept>> GetDeptSelectDataAsync(int? status = null);

        /// <summary>
        /// 获取指定部门及其所有子部门ID列表
        /// </summary>
        /// <param name="deptId">部门ID</param>
        /// <returns>部门ID列表，包含参数指定的部门ID和所有子部门ID</returns>
        Task<List<Guid>> GetDeptAndChildrenIdsAsync(Guid deptId);

        #endregion

        #region 数据验证

        /// <summary>
        /// 检查是否存在子部门
        /// </summary>
        /// <param name="deptId">部门ID</param>
        /// <returns>如果存在子部门返回true，否则返回false</returns>
        Task<bool> HasChildrenAsync(Guid deptId);

        /// <summary>
        /// 检查部门名称是否已存在
        /// </summary>
        /// <param name="name">部门名称</param>
        /// <param name="excludeId">排除的部门ID</param>
        /// <returns>如果名称已存在返回true，否则返回false</returns>
        Task<bool> ExistsByNameAsync(string name, Guid? excludeId = null);

        /// <summary>
        /// 检查部门编码是否已存在
        /// </summary>
        /// <param name="code">部门编码</param>
        /// <param name="excludeId">排除的部门ID</param>
        /// <returns>如果编码已存在返回true，否则返回false</returns>
        Task<bool> ExistsByCodeAsync(string code, Guid? excludeId = null);

        #endregion

        #region 数据操作

        /// <summary>
        /// 更新部门的路径和层级信息
        /// </summary>
        /// <param name="deptId">部门ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateDeptPathAsync(Guid deptId);

        #endregion
    }
}
